package org.emergency.framework.model;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.emergency.framework.constant.ModelConstant;

/**
 * TbEntity entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "TB_DEPARTMENT",  catalog = ModelConstant.DB_CATALOG)
public class TbDepartment implements java.io.Serializable {

	// Fields

	@Id
	@Column(name = "TB_DEPARTMENT_ID", unique = true, length = ModelConstant.STRING_LENGHT_id)
	private String tbDepartmentId;

	@Column(name = "name", length = 50)
	private String name;// 部门名称

	/**
	 * 电话
	 */
	@Column(name = "d_telephone", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String telephone;

	/**
	 * email
	 */
	@Column(name = "d_email", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String email;

	// @Column(name = "parentDepId")
	// private Integer parentDepId = 0;// 父部门ID,一级部门默认0

	// @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
	// "tbDepartment")
	// private Set<TbUserDepartment> tbUserDepartment = new
	// HashSet<TbUserDepartment>(
	// 0);// 和中间表一对多

	@Column(name = "isEnable")
	private boolean isEnable;

	// 以下为备用字段
	@Column(name = "a", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String a;

	@Column(name = "b", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String b;

	@Column(name = "c", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String c;

	@Column(name = "e", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String e;

	@Column(name = "d", nullable = true, length = ModelConstant.STRING_LENGHT_1)
	private String d;
	// 以上为备用字段

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "TB__TB_DEPARTMENT_ID")
	private TbDepartment parentDepartment; // 上级部门

	/*
	 * @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	 * 
	 * @JoinTable(name = "TB_DEPARTMENT_TB_USER", schema =
	 * ModelConstant.DB_SCHEMA, catalog = ModelConstant.DB_CATALOG, joinColumns
	 * = { @JoinColumn(name = "deps_TB_DEPARTMENT_ID", nullable = false,
	 * updatable = false) }, inverseJoinColumns = { @JoinColumn(name =
	 * "users_TB_USER_ID", nullable = false, updatable = false) }) private
	 * Set<TbUser> users = new HashSet<TbUser>(0);
	 */

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tbDepartment")
	private Set<TbUserDepartment> tbUserDepartment = new HashSet<TbUserDepartment>(
			0);// 和用户部门中间表一对多

	@Transient
	private List<TbDepartment> childDepartment = new LinkedList<TbDepartment>();

	// Constructors

	/** default constructor */
	public TbDepartment() {
	}

	public boolean isEnable() {
		return isEnable;
	}

	public void setEnable(boolean isEnable) {
		this.isEnable = isEnable;
	}

	public List<TbDepartment> getChildDepartment() {
		return childDepartment;
	}

	public void setChildDepartment(List<TbDepartment> childDepartment) {
		this.childDepartment = childDepartment;
	}

	/** minimal constructor */
	public TbDepartment(String tbDepartmentId) {
		this.tbDepartmentId = tbDepartmentId;
	}

	public String getTbDepartmentId() {
		return tbDepartmentId;
	}

	public void setTbDepartmentId(String tbDepartmentId) {
		this.tbDepartmentId = tbDepartmentId;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public TbDepartment getParentDepartment() {
		return parentDepartment;
	}

	public void setParentDepartment(TbDepartment parentDepartment) {
		this.parentDepartment = parentDepartment;
	}

	public Set<TbUserDepartment> getTbUserDepartment() {
		return tbUserDepartment;
	}

	public void setTbUserDepartment(Set<TbUserDepartment> tbUserDepartment) {
		this.tbUserDepartment = tbUserDepartment;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getA() {
		return a;
	}

	public void setA(String a) {
		this.a = a;
	}

	public String getB() {
		return b;
	}

	public void setB(String b) {
		this.b = b;
	}

	public String getC() {
		return c;
	}

	public void setC(String c) {
		this.c = c;
	}

	public String getE() {
		return e;
	}

	public void setE(String e) {
		this.e = e;
	}

	public String getD() {
		return d;
	}

	public void setD(String d) {
		this.d = d;
	}

}